package com.spring.bean;

import lombok.Data;
import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @Author: tgy
 * @Date: 2020-08-03 11:19
 */
@Data
public class ConnectionFactoryBean implements FactoryBean<Connection> {

    private String driver;

    private String host = "127.0.0.1";

    private String port = "3306";

    private String database;

    private String username;

    private String password;


    @Override
    public Connection getObject() throws Exception {

        Class.forName(this.driver);
        Connection connection = DriverManager.getConnection("jdbc:mysql://"+this.host+":"+this.port+"/"+this.database+"?useSSL=false", this.username, this.password);
        return connection;
    }

    @Override
    public Class<?> getObjectType() {

        return Connection.class;
    }
}
